//
//  YCUtilityHeader.h
//  Pods
//
//  Created by Apple on 2022/11/4.
//

#ifndef YCUtilityHeader_h
#define YCUtilityHeader_h

#import "UIDevice+YCTools.h"

//屏宽
#define kScreenWidth ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.width)
//屏高
#define kScreenHeight ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? [UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale : [UIScreen mainScreen].bounds.size.height)
//屏的size(宽、高)
#define kScreenSize ([[UIScreen mainScreen] respondsToSelector:@selector(nativeBounds)] ? CGSizeMake([UIScreen mainScreen].nativeBounds.size.width/[UIScreen mainScreen].nativeScale,[UIScreen mainScreen].nativeBounds.size.height/[UIScreen mainScreen].nativeScale) : [UIScreen mainScreen].bounds.size)


//适配比例
#define kScreen_ratio                   (kScreenWidth/375.0)
#define kRatio(r)                       (kScreen_ratio * r)



#define kTabBarHeight          [UIDevice yc_tabBarFullHeight]      // 底部tabbar整体高度 83（49+34）
#define kNavHeight             [UIDevice yc_navigationFullHeight]  // 导航栏整体高度 88 (44+44)
#define kStatusBarHeight       [UIDevice yc_statusBarHeight]       // 44
#define kSafeTopHeight         [UIDevice yc_safeTopHeight]         // 顶部多出的距离 24
#define kSafeBottomHeight      [UIDevice yc_safeBottomHeight]      // 底部多出的距离 34
#define kNavigationBarHeight   [UIDevice yc_navigationBarHeight]   // 导航栏标题高度 44
#define kSafeHeight            kStatusBarHeight                    // 44



#define kLineHeight 0.5f
#define kButtonLineHeight 0.5f


// 弱引用
#define wkSelf __weak typeof(self) weakSelf = self;
// 强引用
#define sgSelf __strong typeof(weakSelf) strongSelf = weakSelf;

#define kWeakify(var) __weak typeof(var) AHKWeak_##var = var;

#define kStrongify(var) \
_Pragma("clang diagnostic push") \
_Pragma("clang diagnostic ignored \"-Wshadow\"") \
__strong typeof(var) var = AHKWeak_##var; \
_Pragma("clang diagnostic pop")


#define kSpace1 1.0f
#define kSpace2 2.0f
#define kSpace3 3.0f
#define kSpace4 4.0f
#define kSpace5 5.0f
#define kSpace6 6.0f
#define kSpace8 8.0f
#define kSpace10 10.0f
#define kSpace12 12.0f
#define kSpace15 15.0f
#define kSpace16 16.0f
#define kSpace20 20.0f
#define kSpace24 24.0f
#define kSpace30 30.0f
#define kSpace32 32.0f
#define kSpace40 40.0f
#define kSpace44 44.0f
#define kCornerRadius3 3.0f
#define kCornerRadius4 4.0f
#define kCornerRadius5 5.0f
#define kCornerRadius8 8.0f

///字体大小
#define kFont(font) [UIFont systemFontOfSize:(font)]
#define kFontMedium(font) [UIFont systemFontOfSize:font weight:UIFontWeightMedium]
#define kFontBold(font) [UIFont systemFontOfSize:font weight:UIFontWeightSemibold]
///常用字体
#define kFontSize16        [UIFont systemFontOfSize:16.f]
#define kFontSize15        [UIFont systemFontOfSize:15.f]
#define kFontSize14        [UIFont systemFontOfSize:14.f]
#define kFontSize13        [UIFont systemFontOfSize:13.f]
#define kFontSize12        [UIFont systemFontOfSize:12.f]
#define kFontSize11        [UIFont systemFontOfSize:11.f]
#define kFontSize10        [UIFont systemFontOfSize:10.f]
#define kFontSize8         [UIFont systemFontOfSize:8.f]
#define kFontMedium8       [UIFont systemFontOfSize:8.0f weight:UIFontWeightMedium]
#define kFontMedium10      [UIFont systemFontOfSize:10.0f weight:UIFontWeightMedium]
#define kFontMedium12      [UIFont systemFontOfSize:12.0f weight:UIFontWeightMedium]
#define kFontMedium13      [UIFont systemFontOfSize:13.0f weight:UIFontWeightMedium]
#define kFontMedium14      [UIFont systemFontOfSize:14.0f weight:UIFontWeightMedium]
#define kFontMedium15      [UIFont systemFontOfSize:15.0f weight:UIFontWeightMedium]
#define kFontMedium16      [UIFont systemFontOfSize:16.0f weight:UIFontWeightMedium]



#define kImgName(imgName) [UIImage imageNamed:(imgName)]



#define kDocumentPath [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) firstObject]
#define kCachePath [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES) firstObject]
#define kTempPath NSTemporaryDirectory()



//APP对象 （单例对象）
#define kApplication [UIApplication sharedApplication]
//主窗口 （keyWindow）
#define kKeyWindow [UIApplication sharedApplication].keyWindow
//APP对象的delegate
#define kAppDelegate  ((AppDelegate *)[UIApplication sharedApplication].delegate)
//NSUserDefaults实例化
#define kUserDefaults [NSUserDefaults standardUserDefaults]
//通知中心 （单例对象）
#define kNotificationCenter [NSNotificationCenter defaultCenter]
//APP版本号
#define kAppVersion [[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleShortVersionString"]
//系统版本号
#define kSystemVersion [[UIDevice currentDevice] systemVersion]
//当前语言
#define kCurrentLanguage ([[NSLocale preferredLanguages] objectAtIndex:0])



#define kDegreesToRadian(x) (M_PI * (x) / 180.0)
#define kRadianToDegrees(radian) (radian * 180.0) / (M_PI)



#define kStartTime CFAbsoluteTime start = CFAbsoluteTimeGetCurrent();
#define kEndTime  NSLog(@"Time: %f", CFAbsoluteTimeGetCurrent() - start)



//拼接字符串
#define StringFormat(FORMAT, ...) [NSString stringWithFormat:FORMAT, ##__VA_ARGS__]
//设置大小
#define Frame(x,y,w,h)  CGRectMake((x), (y), (w), (h))



// 字符串是否为空
#define kIsEmptyString(str) ([str isKindOfClass:[NSNull class]] || str == nil || [str length] < 1 ? YES : NO )
#define ValidString(string) (kIsEmptyString(string) ? @"" : string)
// 数组是否为空
#define kIsEmptyArray(array) (array == nil || [array isKindOfClass:[NSNull class]] || array.count == 0)
// 字典是否为空
#define kIsEmptyDict(dic) (dic == nil || [dic isKindOfClass:[NSNull class]] || dic.allKeys == 0)
// 是否是空对象
#define kIsEmptyObject(_object) (_object == nil \
|| [_object isKindOfClass:[NSNull class]] \
|| ([_object respondsToSelector:@selector(length)] && [(NSData *)_object length] == 0) \
|| ([_object respondsToSelector:@selector(count)] && [(NSArray *)_object count] == 0))



#define IOS8Later           [[[UIDevice currentDevice] systemVersion] floatValue] >= 9.0
#define IOS11Later          [[[UIDevice currentDevice] systemVersion] floatValue] >= 11.0
#define IOS13Later          [[[UIDevice currentDevice] systemVersion] floatValue] >= 13.0
#define IOS15Later          [[[UIDevice currentDevice] systemVersion] floatValue] >= 15.0



#define kUrlWithString(r)    [NSURL URLWithString:r]

/// 安全区高度
NS_INLINE CGFloat k_safeTopHeight(void) {
    UIWindow *mainView = kKeyWindow;
    if (@available(iOS 11.0, *)) {
        return mainView.safeAreaInsets.top;
    } else {
        return 0;
    }
}

// 请求异常提示语
#define YCNETWORK_ANOMALY @"服务繁忙, 请稍后再试"

//判断是否刘海屏
#define iPhoneX (IS_IPHONE_X||IS_IPHONE_Xr||IS_IPHONE_Xs_Max||IS_IPHONE_Xs||IS_IPHONE_12_Mini||IS_IPHONE_12||IS_IPHONE_12_Pro_Max||IS_IPHONE_14_Pro||IS_IPHONE_14_Pro_Max || (k_safeTopHeight() > 0))

//判断是否是iphone
#define kISiPhone (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone)

//判断是否是ipad
#define kISiPad ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad)

//x
#define IS_IPHONE_X ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//xr 11
#define IS_IPHONE_Xr ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(828, 1792), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//xs 11pro
#define IS_IPHONE_Xs ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1125, 2436), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//xsmax  11promax
#define IS_IPHONE_Xs_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1242, 2688), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//12 Mini  13 Mini
#define IS_IPHONE_12_Mini ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1080, 2340), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//12  12Pro  13   13pro   14  14pro
#define IS_IPHONE_12 ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1170, 2532), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//12promax  13promax  14plus
#define IS_IPHONE_12_Pro_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1284, 2778), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//14pro
#define IS_IPHONE_14_Pro ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1179, 2556), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)
//  14promax
#define IS_IPHONE_14_Pro_Max ([UIScreen instancesRespondToSelector:@selector(currentMode)] ? CGSizeEqualToSize(CGSizeMake(1290, 2796), [[UIScreen mainScreen] currentMode].size) && !kISiPad : NO)

#endif /* YCUtilityHeader_h */
